package com.four.controller;

import com.four.entity.Admin;
import com.four.entity.Role;
import com.aliyun.oss.model.LiveChannelListing;
import com.four.entity.Admin;
import com.four.service.AdminService;
import com.four.util.WebUtil;
import com.four.vo.AdminVo;
import com.four.vo.Result;
import com.four.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName:AdminController
 * Description:
 * date:2022/10/13 19:41
 *
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;
    @PostMapping("/admin")
    public Result admin(@RequestBody AdminVo adminVo){
        return adminService.findByAccountAndPass(adminVo.getAccount(),adminVo.getPassword());
    }
    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "1")Integer currentPage,
                       @RequestParam(defaultValue = "5")Integer pageSize
                       ){
        return adminService.findByCondition(currentPage,pageSize);
    }
    @PostMapping("/adminMessage")
    public Result adminMessage(){
        return adminService.selectAdminMessageByid();
    }
    @PostMapping("qr")
    public Result qr(Integer adminId,Integer[] roleIds){

        return  adminService.qr(adminId,roleIds);
    }
    @PostMapping("update")
    public Result update(@RequestBody Admin admin){return adminService.update(admin);}
    @PostMapping("add")
    public Result add(@RequestBody Admin admin){
        return adminService.addAdmin(admin);
    }

    @GetMapping("/headImg")
    public Result headImg(){
        Admin admin = (Admin) WebUtil.getSession().getAttribute("admin");
        Admin adminRes = new Admin();
        adminRes.setAdminUrl(admin.getAdminUrl());
        adminRes.setName(admin.getName());


        return new Result(200,"success",adminRes);

    }
    @PostMapping("updatepassword")
    public Result updatepassword(@RequestBody AdminVo adminVo){
        return adminService.updatePassword(adminVo);
    }
    @PostMapping("delete")
    public Result delete(Integer id){
        return adminService.delete(id);
    }

    @GetMapping("/loginOut")
    public Result loginOut(){
       WebUtil.getSession().invalidate();
       return new Result(200,"退出登录成功");
    }
}
